/*
 * @Author: zhangfeng
 * @Date: 2023-12-27 13:34:19
 * @LastEditTime: 2024-01-09 17:31:41
 * @LastEditors: zhangfeng
 * @Description
 * @FilePath: \manager\managersystem\src\composables\useUsers.ts
 * © 2023 张峰，All rights reserved.
 */

import {
	getUserListAll,
	createUser,
	updateUser,
	deleteUser,
} from '../api/user';

export function useUsers() {
	const loading = ref(true);
	const userTableData = ref([] as UserTableData[]);
	// 获取角色
	const getAllUsers = async () => {
		loading.value = true;
		const res: AxiosResponse = await getUserListAll();
		userTableData.value = res.result;
		loading.value = false;
	};
	// 添加角色
	const createUsers = async (data: UserQuery) => {
		const res = await createUser(data);
		return res;
	};
	// 修改角色
	const updateUsers = async (data: UserQuery) => {
		const res = await updateUser(data);
		return res;
	};
	// 删除角色
	const deleteUsers = async (id: number) => {
		const res = await deleteUser(id);
		return res;
	};
	return {
		loading,
		getAllUsers,
		userTableData,
		createUsers,
		updateUsers,
		deleteUsers,
	};
}
